package org.dreamfly.dreamalarm.service;

import java.util.List;

import org.dreamfly.dreamalarm.Constants;
import org.dreamfly.dreamalarm.bean.Alarm;
import org.dreamfly.dreamalarm.inter.ListComponent;
import org.dreamfly.dreamalarm.task.ListAsyncTask;

import android.content.Intent;
import android.util.Log;

/**
 * 开机启动所有的闹铃
 * 
 * @author Jason_wbw
 *
 */

public class LocalServiceFirstBroadcast extends LocalService implements ListComponent{
	
	@Override
	public void onStart(Intent intent, int startId){
		super.onStart(intent, startId);
		list();
	}

	@Override
	public void list() {
		// TODO Auto-generated method stub
		ListAsyncTask task=new ListAsyncTask(this,this,false);
		task.execute();
	}

	@Override
	public void listSuccessRefresh(List<Alarm> list) {
		// TODO Auto-generated method stub
		Log.d(Constants.LOGTAG,"start brocast all alarms.");
		for(Alarm alarm:list){
			if(alarm.getState()==Alarm.TURN_ON){
				this.broadcastAlarm(alarm);
			}
		}
		this.stopSelf();
	}

	@Override
	public void listErrorRefresh() {
		// TODO Auto-generated method stub
		
	}
}
